#include<stdio.h>
#include<string.h>
const int maxn = 101;
int f[maxn][maxn];
int n;
void floyd(){
	for(int k = 1; k <= n; k++)
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
				if(f[i][k] && f[k][j])f[i][j] = 1;
}
int main()
{
	int m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(f,0,sizeof(f));
		for(int i = 0; i < m; i++){
			int x,y;
			scanf("%d%d",&x,&y);
			f[x][y] = 1;
		}
		floyd();
		int ans = 0;
		for(int i = 1; i <= n; i++){
			int link = 0;
			for(int j = 1; j <= n; j++)
				if(f[i][j] || f[j][i])link++;
			if(link == n-1)ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

